package 第十九章_图形类GUI.事件;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Frame2 extends Frame{
    public TextField textfield=new TextField(20);
    public Button button=new Button("付款");
    public Frame2(){
        this.setSize(400,200);
        this.setLayout(new FlowLayout());
        this.add(textfield);
        this.add(button);
        button.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String money=textfield.getText();
                moneyListener.setmoney(money);
                new Frame3();
            }
        });
        this.setVisible(true);
    }
    // 在frame2类中 生成接口的对象
    public MoneyListener moneyListener;
    public void setMoneyListener(MoneyListener moneyListener){
        this.moneyListener=moneyListener;
    }
    //创建一个接口 MoneyListener
    public interface MoneyListener{
        public void setmoney(String money);
    }


}
